package com.miaostars.myaifriend;

import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
    private ConfigManager configManager;
    private VoiceManager voiceManager;
    private AIHandler aiHandler;

    @Override
    public void onEnable() {
        // 初始化核心模块
        configManager = new ConfigManager(this);
        aiHandler = new AIHandler(configManager);
        voiceManager = new VoiceManager(configManager, aiHandler);
        
        // 注册事件与命令
        getServer().getPluginManager().registerEvents(new AIEntity(this, voiceManager), this);
        getCommand("aivoice").setExecutor(new VoiceCommand(voiceManager));
        
        // 生成默认配置
        saveDefaultConfig();
        getLogger().info("AI语音插件已启动！");
    }

    @Override
    public void onDisable() {
        voiceManager.shutdown();
    }
}

// 语音控制命令
class VoiceCommand implements org.bukkit.command.CommandExecutor {
    private final VoiceManager voiceManager;
    public VoiceCommand(VoiceManager voiceManager) { this.voiceManager = voiceManager; }
    
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (args.length > 0 && "reload".equalsIgnoreCase(args[0])) {
            voiceManager.reloadConfig();
            sender.sendMessage("§a配置已重载！");
            return true;
        }
        return false;
    }
}